package router

import (
	"github.com/gogf/gf/frame/g"
	"github.com/gogf/gf/net/ghttp"
	"github.com/tal-tech/go-zero/core/conf"
	"github.com/tal-tech/go-zero/zrpc"
	"guli-shopping/api-service/api/memberController"
	"guli-shopping/api-service/api/ossController"
	"guli-shopping/api-service/api/productController"
	"guli-shopping/api-service/config"
	"guli-shopping/api-service/protobuff/OssProto"
	"guli-shopping/api-service/protobuff/memberProto"
	"guli-shopping/api-service/protobuff/productProto"
	"os"
)


func init() {
     var configPath string = "/config/application.yml"
	//配置文件在这里初始化
	config := config.GetConfig()
	getwd, _ := os.Getwd()
	conf.MustLoad(getwd+configPath, config)
	server := g.Server()

	//product服务
	server.Group("/product", func(group *ghttp.RouterGroup) {
		zClient := zrpc.MustNewClient(config.Product)
		conn := zClient.Conn()
            group.Group("/category", func(pms_categoryGroup *ghttp.RouterGroup) {
                //获取client
                client := productProto.NewPmsCategoryCheckerClient(conn)
                controller:=&productController.PmsCategoryController{Client:client}
                pms_categoryGroup.GET("/findAll", controller.FindAll)
                pms_categoryGroup.GET("/findById", controller.FindById)
                pms_categoryGroup.POST("/delete", controller.Delete)
                pms_categoryGroup.POST("/update", controller.Update)
                pms_categoryGroup.POST("/save", controller.Save)
                pms_categoryGroup.GET("/findTree", controller.FindTree)
            })


            group.Group("/brand", func(pms_brandGroup *ghttp.RouterGroup) {
                //获取client
                client := productProto.NewPmsBrandCheckerClient(conn)
                controller:=&productController.PmsBrandController{Client:client}
                pms_brandGroup.GET("/findAll", controller.FindAll)
                pms_brandGroup.GET("/findById", controller.FindById)
                pms_brandGroup.POST("/delete", controller.Delete)
                pms_brandGroup.POST("/update", controller.Update)
                pms_brandGroup.POST("/save", controller.Save)
            })

			group.Group("/attr_group", func(pms_attr_groupGroup *ghttp.RouterGroup) {
				//获取client
				client := productProto.NewPmsAttrGroupCheckerClient(conn)
				controller:=&productController.PmsAttrGroupController{Client:client}
				pms_attr_groupGroup.GET("/findAll", controller.FindAll)
				pms_attr_groupGroup.GET("/findById", controller.FindById)
				pms_attr_groupGroup.POST("/delete", controller.Delete)
				pms_attr_groupGroup.POST("/update", controller.Update)
				pms_attr_groupGroup.POST("/save", controller.Save)
				pms_attr_groupGroup.GET("/findGroupByCatId", controller.FindGroupByCatId)
			})
			group.Group("/attr", func(pms_attrGroup *ghttp.RouterGroup) {
				//获取client
				client := productProto.NewPmsAttrCheckerClient(conn)
				controller:=&productController.PmsAttrController{Client:client}
				pms_attrGroup.GET("/findAll", controller.FindAll)
				pms_attrGroup.GET("/findById", controller.FindById)
				pms_attrGroup.POST("/delete", controller.Delete)
				pms_attrGroup.POST("/update", controller.Update)
				pms_attrGroup.POST("/save", controller.Save)
				pms_attrGroup.GET("/findAttrByCatId", controller.FindAttrByCatId)

			})

			group.Group("/category_brand_relation", func(pms_category_brand_relationGroup *ghttp.RouterGroup) {
				//获取client
				client := productProto.NewPmsCategoryBrandRelationCheckerClient(conn)
				controller:=&productController.PmsCategoryBrandRelationController{Client:client}
				pms_category_brand_relationGroup.GET("/findAll", controller.FindAll)
				pms_category_brand_relationGroup.GET("/findById", controller.FindById)
				pms_category_brand_relationGroup.POST("/delete", controller.Delete)
				pms_category_brand_relationGroup.POST("/update", controller.Update)
				pms_category_brand_relationGroup.POST("/save", controller.Save)
				pms_category_brand_relationGroup.GET("/findAllByBrandId", controller.FindAllByBrandId)
			})

		group.Group("/attr_attrgroup_relation", func(pms_attr_attrgroup_relationGroup *ghttp.RouterGroup) {
			//获取client
			client := productProto.NewPmsAttrAttrgroupRelationCheckerClient(conn)
			controller:=&productController.PmsAttrAttrgroupRelationController{Client:client}
			pms_attr_attrgroup_relationGroup.GET("/findAll", controller.FindAll)
			pms_attr_attrgroup_relationGroup.GET("/findById", controller.FindById)
			pms_attr_attrgroup_relationGroup.POST("/delete", controller.Delete)
			pms_attr_attrgroup_relationGroup.POST("/update", controller.Update)
			pms_attr_attrgroup_relationGroup.POST("/save", controller.Save)
			pms_attr_attrgroup_relationGroup.GET("/findAllAssociatedAttr", controller.FindAllAssociatedAttr)
			pms_attr_attrgroup_relationGroup.GET("/findAllNoAssociatedAttr", controller.FindAllNoAssociatedAttr)
			pms_attr_attrgroup_relationGroup.GET("/findAllSaleAssociatedAttr", controller.FindAllSaleAssociatedAttr)
			pms_attr_attrgroup_relationGroup.GET("/findAllSaleNoAssociatedAttr", controller.FindAllSaleNoAssociatedAttr)
		})
	})

	//oss服务
	server.Group("/oss", func(group *ghttp.RouterGroup){
		zClient := zrpc.MustNewClient(config.Oss)
		conn := zClient.Conn()
		//获取client
		client := OssProto.NewOssCheckerClient(conn)
		controller:=&ossController.OssController{Client:client}
		group.GET("/getAuthUrl",controller.GetAuthUrl)
	})

	//member服务
	server.Group("/member", func(ums_member_levelGroup *ghttp.RouterGroup) {
		zClient := zrpc.MustNewClient(config.Member)
		conn := zClient.Conn()
		ums_member_levelGroup.Group("/ums_member_level", func(group *ghttp.RouterGroup) {
			//获取client
			client := memberProto.NewUmsMemberLevelCheckerClient(conn)
			controller:=&memberController.UmsMemberLevelController{Client:client}
			group.GET("/findAll", controller.FindAll)
			group.GET("/findById", controller.FindById)
			group.POST("/delete", controller.Delete)
			group.POST("/update", controller.Update)
			group.POST("/save", controller.Save)
		})

	})


}
